using UnityEngine;

[CreateAssetMenu(fileName = "Freeze eneimes effect", menuName = "Data/Item effect/Freeze enemies")]
public class FreezeEnemiesEffect : ItemEffect
{
    [SerializeField] private float duration;

    public override void ExecuteEffect(Transform transform, Player player)
    {
        PlayerStats playerStats = player.GetComponent<PlayerStats>();
        if (playerStats.CurrentHp > playerStats.GetMaxHp() * 0.1f)
            return;
        if (!player.Inventory.CanUseArmor())
            return;
        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 2f);
        foreach (Collider2D collider in colliders)
        {
            collider.GetComponent<Enemy>()?.FreezeTimeFor(duration);
        }
    }
}
